<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class StoreCategory extends Model
{
    protected $table = 'eb_store_category';

    public $timestamps = false;

    /**
     * 获取所有
     * @auther yang
     * @param $where
     * @param array $fileds
     * @return mixed
     */
    public static function getAll($where, $fileds = ['*'])
    {
        $db = format_sql(new StoreCategory(), $where);
        return $db->select($fileds)
            ->get()->toArray();
    }

    /**
     * 列表
     * @auther yang
     * @param $where
     * @param array $page
     * @param array $fileds
     * @return mixed
     */
    public static function list($where, $page = [0, 20], $fileds = ['*'])
    {
        $db = format_sql(new StoreCategory(), $where);
        return $db->select($fileds)
            ->offset($page[0])
            ->limit($page[1])
            ->get();
    }


    /**
     * 取一条数据
     * @auther yang
     * @param $where
     * @param array $fileds
     * @return mixed
     */
    public static function detail($where, $fileds = ['*'])
    {
        $db = format_sql(new StoreCategory(), $where);
        return $db->select($fileds)->first();
    }

    /**
     * 修改
     * @auther yang
     * @param $where
     * @param $data
     * @return mixed
     */
    public static function edit($where, $data)
    {
        $db = format_sql(new StoreCategory(), $where);
        return $db->update($data);
    }

}
